package com.example.inventoryservice.WarehouseQueryDemo;

import java.util.ArrayList;
import java.util.List;

// 按会计主体及相关组织过滤的具体策略
public class AccountingEntityFilterStrategy implements WarehouseFilterStrategy  {
    @Override
    public List<Warehouse> filter(List<Warehouse> allWarehouses, String inventoryOrg, String accountingEntity) {
        List<Warehouse> result = new ArrayList<>();
        for (Warehouse warehouse : allWarehouses) {
            // 满足以下任一条件的仓库都会被选中：
            // 1. 属于该会计主体
            // 2. 属于该会计主体的下属库存组织
            // 3. 具有核算委托的库存组织
            if (accountingEntity.equals(warehouse.getAccountingEntity()) || warehouse.isHasDelegation()) {
                result.add(warehouse);
            }
        }
        return result;
    }
}
